package.path = package.path .. ";../?.lua;"
package.cpath = package.cpath .. ";../../c2al/test/ogl/?.dll;"
package.path = package.path .. ";../../c2al/llib/?.lua;"
require("llui");
window = Window();
local widget = Widget();
widget.backgroundcolor = 0xff0000ff;
widget.x = 100;
widget.y = 100;
widget.width = 100;
widget.height = 100;
local widget2 = Widget();
widget2.backgroundcolor = 0xff00ff00;
widget2.x = 200;
widget2.y = 100;
widget2.width = 80;
widget2.height = 30;
widget2.text = "hello";
Style.button(widget2);
window:add(widget2);
window:add(widget);

fastRender = true;
fastRender = false;
--renderType = "real-time rendering";
for k=1,0x0,1 do
    local widget = Widget();
    widget.x = (k&0xff)*2;
    widget.y = (k>>8)*10;
    --widget.lowRender = true;

    --[[
    ryzen 1700 
    widgets    CPU  flag               
    0x100      4%   fast=false | type='real-time'
    0x1000     4%   fast=true
    0x1000     6%   fast=false | type=nil
    0x1000     11%  fast=false | type='real-time'

    Note:
    fast=false :create texture,render target texture
    fast=ture  :render window
    type='real-time'  :widget.lowRender = true;    widget:LockRender(); render....;  widget:UnlockRender();

    ]]

    widget.render = function(self)
        self.backgroundcolor = self.backgroundcolor + 0x10000;
        if(fastRender)then
            drawRect(self.x,self.y,self.width,self.height,self.backgroundcolor,true);
        else
            if(renderType=="real-time rendering")then
                self.lowRender = true;
            end
            if(self:LockRender())then
                --render draw texture
                drawRect(0,0,self.width,self.height,self.backgroundcolor,true);
                self:UnlockRender();
            end
        end
    end
    widget.backgroundcolor = 0xff00ff00+k;
    window:add(widget);
end

local menu = PopupMenu();
menu.menulist = {
    {"File"},
    {"Edit"}
}
menu.x = 100;
menu.y = 200;
menu.shown = false;
window:add(menu);

window.mousebuttonup = function(self,event)
    local x =  event.x;
    local y =  event.y;
    if(x>=self.x and x<=(self.x+self.width) and y>=self.y and y<=(self.y+self.height))then
        menu.x = x + 1;
        menu.y = y + 1;
        menu.selectX = 1;
        menu.selectY = 1;
        menu.shown = true;
        return true;
    else
    end
end
menu.mousemotion = function(self,event)
    local x =  event.x;
    local y =  event.y;
    if(x>=self.x and x<=(self.x+self.width) and y>=self.y and y<=(self.y+self.height))then
        self.selectX = x - menu.x;
        self.selectY = y - menu.y;
        return true;
    else
        self.selectX = nil;
        self.selectY = nil;
        self.selectIndex = 0;
    end
end


window:SetTitle("test1");
window:show();
window:SetTitle("test3");
application.addWidget(window);
application.run();


--like json
--[[
local w = {
    window = {
        type = Window(),
        width = 680,
        height = 480,
        shown = true,
        {
            {type=Button(),text="click", width = 100,height = 30,x = 0,y=0},
            {type=Button(),text="click2", width = 100,height = 30,x = 0,y=30},
            {type=Button(),text="click3", width = 100,height = 30,x = 0,y=30*2},
        }
    }
}
]]


